package org.lzh.service;

import org.lzh.dao.ProblemDao;
import org.lzh.pojo.Problem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProblemService {
    //注入dao
    @Autowired
    protected ProblemDao problemDao;

    //新建问题
    public int insertProblem(Problem problem){
        return problemDao.insertProblem(problem);
    }


    //根据id删除该问题
    public int deleteById(Integer id){
        return problemDao.deleteById(id);
    }


    //根据id查找问题
    public Problem findById(String id){
        return problemDao.findById(id);
    }


    //根据id更新问题
    public int updateById(Problem p ){return  problemDao.updateById(p);}


    //动态查询学生用户
    public List<Problem> findByDynamic1(Problem problem){
        return problemDao.findByDynamic(problem);
    }

    //动态查询学生用户（分页）
    public List<Problem> findByDynamic(Problem user,int currPage, int pageSize) {
        //查询全部数据
        List<Problem> students = problemDao.findByDynamic(user);
        //总数据的长度
        int length=students.size();
        //从第几条数据开始
        int firstIndex = (currPage - 1) * pageSize;
        //到第几条数据结束
        int lastIndex = currPage * pageSize<length?currPage * pageSize:length;
        return students.subList(firstIndex, lastIndex); //直接在list中截取

    }
}
